package com.xuecheng.media.controller;

import com.xuecheng.api.media.MediaApi;
import com.xuecheng.api.media.model.dto.MediaDTO;
import com.xuecheng.api.media.model.qo.QueryMediaModel;
import com.xuecheng.api.media.model.vo.MediaVO;
import com.xuecheng.common.domain.page.PageRequestParams;
import com.xuecheng.common.domain.page.PageVO;
import com.xuecheng.common.domain.response.RestResponse;
import com.xuecheng.common.util.SecurityUtil;
import com.xuecheng.media.convert.MediaConvert;
import org.springframework.web.bind.annotation.*;
import com.xuecheng.media.service.MediaService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * <p>
 * 媒资信息 前端控制器
 * </p>
 *
 * @author itcast
 */
@Slf4j
@RestController
public class MediaController implements MediaApi {

    @Autowired
    private MediaService  mediaService;


    @Override
    @PostMapping("/media")
    public MediaDTO createMedia(@RequestBody MediaVO mediaVO) {
        Long companyId = SecurityUtil.getCompanyId();
        MediaDTO mediaDTO = MediaConvert.INSTANCE.vo2dto(mediaVO);
        return  mediaService.createMedia(mediaDTO,companyId);
    }

    @Override
    @PostMapping("/media/list")
    public PageVO<MediaDTO> queryMediaPage(PageRequestParams param , @RequestBody QueryMediaModel queryMediaModel) {
        Long companyId = SecurityUtil.getCompanyId();
        return mediaService.queryMediaPage(param,queryMediaModel,companyId);
    }

    @Override
    @PostMapping("/m/media/list")
    public PageVO<MediaDTO> queryMediaPageM(PageRequestParams param , @RequestBody QueryMediaModel queryMediaModel) {
//        Long companyId = SecurityUtil.getCompanyId();
        return mediaService.queryMediaPage(param,queryMediaModel,null);
    }


    @Override
    @GetMapping("/media/preview/{mediaId}")
    public String getMedia(@PathVariable Long mediaId) {
        Long companyId = SecurityUtil.getCompanyId();
        String str = mediaService.getMediaById(mediaId,companyId);
        return str;
    }

    @GetMapping("/m/media/preview/{mediaId}")
    public String getMMedia(@PathVariable Long mediaId) {
        Long companyId = SecurityUtil.getCompanyId();
        String str = mediaService.getMediaById(mediaId,companyId);
        return str;
    }

    @Override
    @DeleteMapping("/media/{mediaId}")
    public boolean deleteMediaById(@PathVariable Long mediaId) {
        Long companyId = SecurityUtil.getCompanyId();
        boolean state = mediaService.deleteMediaById(mediaId,companyId);
        return state;
    }

    @GetMapping("/l/media/{mediaId}")
    public RestResponse<MediaDTO> getMedia4s(@PathVariable  Long mediaId){
        return mediaService.getMedia4s(mediaId);
    }

    @PutMapping("/m/media/audit")
    public boolean modifyMediaAudit(@RequestBody MediaVO vo) {
        MediaDTO mediaDTO = MediaConvert.INSTANCE.vo2dto(vo);
        return mediaService.modifyMediaAudit(mediaDTO);
    }
}
